package columns

import (
	"GraduationProject/public/db"
	"GraduationProject/public/models"
	"GraduationProject/webserver/controllers/util"
	"github.com/gin-gonic/gin"
)

func Columns(c *gin.Context) {
	_, err := util.UserFilter(c)
	if err != nil {
		return
	}

	var count int
	db.DB.Model(&models.Columns{}).Count(&count)
	var columns []models.Columns
	db.DB.Limit(c.PostForm("limit")).Preload("Seed").
		Offset(c.PostForm("offset")).Order("id desc").Find(&columns)

	c.JSON(200, gin.H{
		"status":  10000,
		"message": "success",
		"columns": columns,
		"count":   count,
	})
}
